<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>根据我的心情换个网页背景</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            background: url('./img/3.png') no-repeat center top;
            background-size: 30%;
        }
        
        li {
            list-style: none;
        }
    </style>
</head>

<body>
    <ul>
        <li><img src="./img/1.png" width="100px" alt=""></li>
        <li><img src="./img/2.png" width="100px" alt=""></li>
        <li><img src="./img/3.png" width="100px" alt=""></li>
        <li><img src="./img/4.png" width="100px" alt=""></li>
    </ul>
</body>

</html>
<script>
    let imgs = window.document.querySelectorAll('img');
    for (let index = 0; index < imgs.length; index++) {
        const element = imgs[index];
        element.onmouseover = function(param) {
            window.document.body.style.backgroundImage = 'url(' + this.src + ')';
        };
    }
</script>